/**
 * 
 */
package com.dhcc.DRGsHosp.facade.impl;

import com.dhcc.DRGsHosp.application.DictionaryDataApplication;
import com.dhcc.DRGsHosp.facade.DictionaryDataFacade;
import com.dhcc.DRGsHosp.facade.dto.DictionaryDataDTO;
import com.dhcc.DRGsHosp.facade.impl.assembler.DictionaryDataAssembler;
import org.codehaus.jackson.map.ObjectMapper;
import org.dayatang.domain.InstanceFactory;
import org.dayatang.querychannel.QueryChannelService;
import org.openkoala.koala.commons.InvokeResult;
import org.springframework.beans.factory.annotation.Autowired;

import javax.inject.Named;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author chl
 *
 */
@Named("drgsHospFacadeImpl9")
public class DictionaryDataFacadeImpl implements DictionaryDataFacade {
	
	@Autowired
	private DictionaryDataApplication  application;
	
	private QueryChannelService queryChannel;

    private QueryChannelService getQueryChannelService(){
       if(queryChannel==null){
          queryChannel = InstanceFactory.getInstance(QueryChannelService.class,"queryChannel");
       }
     return queryChannel;
    }
	

	/* (non-Javadoc)
	 * @see com.dhcc.DRGsHosp.facade.DictionaryDataFacade#findAllDictionaryData()
	 */
	@Override
	public List<DictionaryDataDTO> findAllDictionaryData() {
		// TODO Auto-generated method stub
		return (DictionaryDataAssembler.toDTOs(application.findAllDictionaryData())) ;
	}


	/* (non-Javadoc)
	 * @see com.dhcc.DRGsHosp.facade.DictionaryDataFacade#getDictionaryData(java.lang.Integer)
	 */
	@Override
	public InvokeResult findDictionaryDataById(Integer id) {
		// TODO Auto-generated method stub
		return InvokeResult.success(DictionaryDataAssembler.toDTO(application.getDictionaryDataById(id))) ;
	}

	/**
	 *  @Description：获取字典明细
	 *  @Author lhj 
	 *  @see com.dhcc.DRGsHosp.facade.DictionaryDataFacade#findDictionaryDataByCode(java.lang.String)
	 */
	@Override
	public InvokeResult findDictionaryDataByCode(String dicCode) {
		List<Map<String, Object>> resultList = application.findDictionaryDataByCode(dicCode) ;
		return InvokeResult.success(resultList);
	}

	/* (non-Javadoc)
	 * @see com.dhcc.DRGsHosp.facade.DictionaryDataFacade#delInvalidDictionaryDatas(java.lang.String, java.lang.String)
	 */
	@Override
	public void delInvalidDictionaryDatas(String param, String dicCode) {
		application.delInvalidDictionaryDatas(param,dicCode);
	}

	/**
	 * 
	 *  @Description：保存字典详情
	 *  @Author lhj 
	 *  @see com.dhcc.DRGsHosp.facade.DictionaryDataFacade#saveDictionayData(java.lang.String)
	 */
	@Override
	public void saveDictionayData(String param) {
		// saveOrUpdate根据是否有ID判断 。 指定字段更新。
		ObjectMapper objectMapper = new ObjectMapper();
		Map<String, Object> json;
		try {
			json = objectMapper.readValue(param, Map.class);
		} catch (Exception e) {
			e.printStackTrace();
			json = new HashMap<String, Object>();
		} 
		 application.saveDictionaryData(json);
	}
}
